package com.zzwtec.validation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

import com.zzwtec.validation.annotation.NotBlank;

/**
 * 不能为空白校验器
 * @author 草原狼
 *
 */
public class NotBlankValidator implements AnnotationValidator {
	
	/**
	 * 校验字段f的值不能为null或者是空字符串，校验结果保存在result中
	 */
	@Override
	public ValidateResult validate(Field f, Object value) {
		ValidateResult result = new ValidateResult();
		if(f.isAnnotationPresent(NotBlank.class)){
			NotBlank notBlank = f.getAnnotation(NotBlank.class);
			if(value == null || value.toString().length() == 0){
				result.setMessage(notBlank.fieldName() + "不能为空");
			}
		}
		return result;
	}
	
	private String name;
	
	@Override
	public String getName() {		
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;		
	}

	@Override
	public Class<? extends Annotation> getAnnotationClass() {
		return NotBlank.class;
	}

}
